package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements search user in the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageSearchBussines {
	
	private ConnectionToClient client ;
	private String[] str; 
	static int row1;

/**
 * Contractor of this class 
 * @param str
 * @param client
 */
	public MessageSearchBussines(String[] str, ConnectionToClient client){
		
		this.client= client ;
		this.str= str; 	
	
	}
	
	/**
	 * This method is searching the business card in the DB 
	 * @throws SQLException
	 * @throws IOException
	 */
	public void SearchBussines() throws SQLException, IOException{
	
				SQLConnection sc = new SQLConnection();
			
				java.sql.PreparedStatement bid = sc.getConnection().prepareStatement("SELECT * FROM db.business Where BusinessId ='"+str[1]+"';");
				ResultSet bidrs= bid.executeQuery();

		
				
				if (!bidrs.next() )
				{
					client.sendToClient("BussinesNotFound");

				}
		
	
				
				else{				
										
					
										ArrayList<Object> bus=new ArrayList<Object>();
										bus.add("SearchBussines");
										bus.add(bidrs.getString(1));
										bus.add(bidrs.getString(2));
										bus.add(bidrs.getString(3));
										bus.add(bidrs.getString(4));
										bus.add(bidrs.getString(5));
										bus.add(bidrs.getString(6));
										
										
										client.sendToClient(bus);
									
								
								}
	
}
}

				
				        	
			


